package com.java.framework.advice;

import com.java.framework.web.controller.BaseController;
import com.java.framework.web.domain.AjaxResult;
import org.springframework.beans.TypeMismatchException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice(basePackages = {"com.java.project.controller"})
public class MyControllerAdvice extends BaseController {

	//400错误->缺少参数异常
    @ExceptionHandler({MissingServletRequestParameterException.class})
    @ResponseBody
    public AjaxResult requestMissingServletRequest(MissingServletRequestParameterException ex){
    	return AjaxResult.error("参数不能为空");
    }
    
    //400错误->参数类型异常
    @ExceptionHandler({TypeMismatchException.class})
    @ResponseBody
    public AjaxResult requestTypeMismatch(TypeMismatchException ex){
    	return AjaxResult.error("参数类型不正确");
    }

}
